$(function() {
  const form = layui.form
  const layer = layui.layer

  form.verify({
    pwd: [/^[\S]{6,12}$/, '密码必须6到12位,且不能出现空格'],
    samePwd: function(value) {
      if (value === $('[name=oldPwd]').val()) {
        return '新旧密码不能相同！'
      }
    },
    rePwd: function(value) {
      if (value !== $('[name=newPwd]').val()) {
        return '两次密码不一致！'
      }
    }
  })


  // 重置密码功能
  postReset()
  function postReset() {
    $("#formReset").on("submit", function (e) {
      e.preventDefault();
      $.ajax({
        method: "post",
        url: "/my/updatepwd",
        data: $(this).serialize(),
        success: function (res) {
          console.log(res);
          if(res.status !== 0){
            return layer.msg(res.message)
          }
          layer.msg(res.message)
          // 重置表单
          localStorage.removeItem('token-DSJ')
          window.parent.location.href = '/login.html'
        },
      });
    });
  }
})